import QtQuick 2.11

import "."
import "_Global"
import "_Global/Button"

import "_Global/Global.js" as GlobalJS
import "GameJS.js" as GameJS

/*
  选择年级(初中,高中,四六级)界面
*/

Item {
    signal s_choiceClass(int classId)       //选择信号
    signal s_close()                    //关闭信号
    signal showConfig()

    id: root
    anchors.fill: parent

    Image { //背景
        id: backImage
        source: Global._FixResourcePath_R("Media/Images/Grades/Back.png")
        anchors.fill: parent
    }

    ImageButton2 {  //设置
        x: Global.dpW(1820)
        y: Global.dpH(0)
        width: Global.dpW(100)
        height: Global.dpH(100)
        source: Global._FixResourcePath_R("Media/Images/Exit/Config.png")
        soundEffectClick: Global.resource.effects.effectButton
        bEffectOn: Global.config.bEffectOn
        onButtonClicked: {
            showConfig();
        }
    }


    Item {
        id: mainPage
        anchors.fill: parent

        ImageButton2 {
            id: buttonReturn
            x: Global.gamePos.mapGameGrade.rectReturn.x
            y: Global.gamePos.mapGameGrade.rectReturn.y
            width: Global.gamePos.mapGameGrade.rectReturn.width
            height: Global.gamePos.mapGameGrade.rectReturn.height
            source: Global._FixResourcePath_R("Media/Images/Return.png")
            soundEffectClick: Global.resource.effects.effectButton
            bEffectOn: Global.config.bEffectOn

            onButtonClicked: {
                s_close();
            }
        }

    }

    Item {
        id: page2
        anchors.fill: parent
        visible: false

        ImageButton2 {
            id: buttonReturn2
            x: Global.gamePos.mapGameGrade.rectReturn.x
            y: Global.gamePos.mapGameGrade.rectReturn.y
            width: Global.gamePos.mapGameGrade.rectReturn.width
            height: Global.gamePos.mapGameGrade.rectReturn.height
            source: Global._FixResourcePath_R("Media/Images/Return.png")
            soundEffectClick: Global.resource.effects.effectButton
            bEffectOn: Global.config.bEffectOn

            onButtonClicked: {
                mainPage.visible = true;
                page2.visible = false;
            }
        }
    }



    Component {
        id: classComp

        ImageButton2 {
            property int classID

            id: buttonClass
            width: Global.gamePos.mapGameGrade.sizeButton.width
            height: Global.gamePos.mapGameGrade.sizeButton.height

            soundEffectClick: Global.resource.effects.effectButton
            bEffectOn: Global.config.bEffectOn

            onButtonClicked: {
                _private.choiceClass(classID)
            }
        }

    }

    QtObject {
        id: _private

        //选择id,-1为换页
        function choiceClass(id) {
            console.debug("choice Class:",id)
            if(id == -1) {
                page2.visible = true;
                mainPage.visible = false;
            }
            else
                s_choiceClass(id)
        }
    }

    Component.onCompleted: {
        classComp.createObject(mainPage,
                                         {
                                             "x": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton1.x}),
                                             "y": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton1.y}),
                                             "classID": -1,
                                             "source": Global._FixResourcePath_R("Media/Images/Grades/ChuZhong.png")
                                         });

        classComp.createObject(mainPage,
                                         {
                                             "x": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton2.x}),
                                             "y": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton2.y}),
                                             "classID": 6,
                                             "source": Global._FixResourcePath_R("Media/Images/Grades/GaoZhong.png")
                                         });

        classComp.createObject(mainPage,
                                         {
                                             "x": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton3.x}),
                                             "y": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton3.y}),
                                             "classID": 7,
                                             "source": Global._FixResourcePath_R("Media/Images/Grades/SiJi.png")
                                         });

        classComp.createObject(mainPage,
                                         {
                                             "x": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton4.x}),
                                             "y": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton4.y}),
                                             "classID": 8,
                                             "source": Global._FixResourcePath_R("Media/Images/Grades/LiuJi.png")
                                         });



        classComp.createObject(page2,
                                         {
                                             "x": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton5.x}),
                                             "y": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton5.y}),
                                             "classID": 1,
                                             "source": Global._FixResourcePath_R("Media/Images/Grades/QiNianJiShang.png")
                                         });

        classComp.createObject(page2,
                                         {
                                             "x": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton6.x}),
                                             "y": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton6.y}),
                                             "classID": 2,
                                             "source": Global._FixResourcePath_R("Media/Images/Grades/QiNianJiXia.png")
                                         });

        classComp.createObject(page2,
                                         {
                                             "x": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton7.x}),
                                             "y": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton7.y}),
                                             "classID": 3,
                                             "source": Global._FixResourcePath_R("Media/Images/Grades/BaNianJiShang.png")
                                         });

        classComp.createObject(page2,
                                         {
                                             "x": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton8.x}),
                                             "y": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton8.y}),
                                             "classID": 4,
                                             "source": Global._FixResourcePath_R("Media/Images/Grades/BaNianJiXia.png")
                                         });

        classComp.createObject(page2,
                                         {
                                             "x": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton9.x}),
                                             "y": Qt.binding(function(){return Global.gamePos.mapGameGrade.pointButton9.y}),
                                             "classID": 5,
                                             "source": Global._FixResourcePath_R("Media/Images/Grades/JiuNianJi.png")
                                         });

    }

}
